package com.rams.jhms.fs;

import java.io.File;

import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;

import com.rams.jhms.dto.MediaFileDTO;
import com.rams.jhms.logging.BaseLogger;

public class MediaInfoReader {

	public MediaFileDTO readTags(File mf) {
		MediaFileDTO f = new MediaFileDTO(); 
		try {
			if (mf.isDirectory())
				return null; 
				
			AudioFile af = AudioFileIO.read(mf);
			Tag tag = af.getTag();
			String a = tag.getFirst(FieldKey.TITLE);
			f.setArtist(tag.getFirst(FieldKey.ARTIST));
			f.setAlbum(tag.getFirst(FieldKey.ALBUM));
			f.setTitle(a);
			f.setComment(tag.getFirst(FieldKey.COMMENT));
			f.setYear(tag.getFirst(FieldKey.YEAR));
			f.setTrack(tag.getFirst(FieldKey.TRACK));
			f.setDickNo(tag.getFirst(FieldKey.DISC_NO));
			f.setComposer(tag.getFirst(FieldKey.COMPOSER));
		} catch (Exception e) {
			BaseLogger.debug(e);
		}
		return f;
	}
}
